package com.yixun.qfbao.api.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yixun.qfbao.api.service.MapService;
import com.yixun.qfbao.constant.BMapConstant;
import com.yixun.qfbao.model.bmap.BMapGeocodingResult;
import com.yixun.qfbao.util.RestTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author jhsong
 * @create 2020-10-12
 **/
@Slf4j
@Service
public class MapServiceImpl implements MapService {

    @Override
    public BMapGeocodingResult getBMapInfoByAddress(String address) {
        String url = BMapConstant.BMAP_URL + BMapConstant.BMAP_GEOCODING;
        url = url.replace("${address}", address).replace("${ak}", BMapConstant.AK);
        log.info("BMap getBMapInfoByAddress URL: {}", url);
        String result = RestTemplateUtil.get(url);
        log.info("BMap getBMapInfoByAddress result: {}", result);
        return JSONObject.parseObject(result, BMapGeocodingResult.class);
    }
}
